package com.dp.iot.admin.api.iotcollectionmode;

import com.dp.iot.core.service.CommonRestController;
import org.springframework.beans.factory.InitializingBean;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.math.*;
import java.util.List;
import java.util.Map;
import com.dp.iot.core.common.constant.PageConstant;
import com.dp.iot.core.common.exception.BusinessException;
import com.dp.iot.core.serialize.ResponseMsg;
import com.dp.iot.model.IotCollectionMode;
import com.dp.iot.service.iotcollectionmode.service.IotCollectionModeService;

import com.dp.iot.core.utils.ListUtil;
import com.dp.iot.core.utils.MapUtil;
import com.dp.iot.core.utils.StringUtil;


/**
* 代码为自动生成 Created by www.magicalcoder.com
* 如果你改变了此类 read 请将此行删除
* 欢迎加入官方QQ群:323237052
*/

@RequestMapping("/admin/iot_collection_mode_rest/")
@RestController
public class AdminIotCollectionModeRestController extends CommonRestController<IotCollectionMode,String> implements InitializingBean
{

    @Resource
    private IotCollectionModeService iotCollectionModeService;

    //分页查询
    @RequestMapping(value={"page"}, method={RequestMethod.GET})
    public ResponseMsg page(
        @RequestParam(required = false,value ="collectionModeIdFirst")                            String collectionModeIdFirst ,
        @RequestParam(required = false,value ="collectionModeNameFirst")                            String collectionModeNameFirst ,
        @RequestParam(required = false,value ="collectionModeVersionFirst")                            String collectionModeVersionFirst ,
        @RequestParam(required = false,value ="collectionModeSerialNumFirst")                            Integer collectionModeSerialNumFirst ,
        @RequestParam(required = false,value ="collectionModeStatusFirst")                            String collectionModeStatusFirst ,
        @RequestParam(required = false,value ="collectionModeTypeFirst")                            String collectionModeTypeFirst ,
        @RequestParam(required = false,value ="remarksFirst")                            String remarksFirst ,
        @RequestParam(required = false,value ="creationTimeFirst")                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date creationTimeFirst ,
        @RequestParam(required = false,value ="creationTimeSecond")                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date creationTimeSecond ,
        @RequestParam(required = false,value ="creationUserFirst")                            String creationUserFirst ,
        @RequestParam(required = false,value ="updateTimeFirst")                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date updateTimeFirst ,
        @RequestParam(required = false,value ="updateTimeSecond")                    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date updateTimeSecond ,
        @RequestParam(required = false,value ="updateUserFirst")                            String updateUserFirst ,
        @RequestParam(required = false,value ="spare1First")                            String spare1First ,
        @RequestParam(required = false,value ="spare2First")                            String spare2First ,
        @RequestParam(required = false,value ="spare3First")                            String spare3First ,
        @RequestParam int page,@RequestParam int limit,@RequestParam(required = false) String safeOrderBy)
    {
        limit = Math.min(limit, PageConstant.MAX_LIMIT);
        int start = (page - 1) * limit;
        Map<String,Object> query = new HashedMap();
        query.put("collectionModeIdFirst",coverBlankToNull(collectionModeIdFirst));
        query.put("collectionModeNameFirst",coverBlankToNull(collectionModeNameFirst));
        query.put("collectionModeVersionFirst",coverBlankToNull(collectionModeVersionFirst));
        query.put("collectionModeSerialNumFirst",collectionModeSerialNumFirst);
        query.put("collectionModeStatusFirst",coverBlankToNull(collectionModeStatusFirst));
        query.put("collectionModeTypeFirst",coverBlankToNull(collectionModeTypeFirst));
        query.put("remarksFirst",coverBlankToNull(remarksFirst));
        query.put("creationTimeFirst",creationTimeFirst);
        query.put("creationTimeSecond",creationTimeSecond);
        query.put("creationUserFirst",coverBlankToNull(creationUserFirst));
        query.put("updateTimeFirst",updateTimeFirst);
        query.put("updateTimeSecond",updateTimeSecond);
        query.put("updateUserFirst",coverBlankToNull(updateUserFirst));
        query.put("spare1First",coverBlankToNull(spare1First));
        query.put("spare2First",coverBlankToNull(spare2First));
        query.put("spare3First",coverBlankToNull(spare3First));
        Integer count = iotCollectionModeService.getModelListCount(query);
        query.put("start",start);
        query.put("limit",limit);
        if(StringUtil.isBlank(safeOrderBy)){
            query.put("notSafeOrderBy","collection_mode_id desc");
        }else{
            query.put("safeOrderBy",safeOrderBy);
        }
        return new ResponseMsg(count,iotCollectionModeService.getModelList(query));
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        super.commonService = iotCollectionModeService;
        super.primaryKey = "collectionModeId";//硬编码此实体的主键名称
    }
}
